package com.wwwc.index.web.servlet;

import java.io.*;
import java.util.*;

import javax.servlet.*;
import javax.servlet.http.*;
import java.text.DecimalFormat;

import javax.servlet.ServletRequestWrapper;
import javax.ejb.*;
import javax.naming.*;
import java.rmi.*;
import javax.rmi.*;

import com.wwwc.util.web.*;
import com.wwwc.index.web.ejb.database.*;

public class ScheduleD extends ScheduleDServlet {
    public StringBuffer getOptionBar(String call_path, String mid, String add_aid, String view_aid, 
				     String admin_aid, String manager_aid, String user_name, int user_level, 
				     boolean manager, boolean admin) {
	StringBuffer sbf = new StringBuffer();
	sbf.append("\n<TABLE border='0' align='center'>");
	sbf.append("\n<TR>");
	sbf.append(MyHtml.makeLinkCell("Add", call_path+"?mid="+mid+"&aid="+add_aid));
	sbf.append(MyHtml.makeLinkCell("View", call_path+"?mid="+mid+"&aid="+view_aid));
	if(manager) {
	    sbf.append(MyHtml.makeLinkCell("Manager", call_path+"?mid="+mid+"&aid="+manager_aid));
	}
	if(admin) {
	    sbf.append(MyHtml.makeLinkCell("Manager", call_path+"?mid="+mid+"&aid="+manager_aid));
	    sbf.append(MyHtml.makeLinkCell("Admin", call_path+"?mid="+mid+"&aid="+admin_aid));
	}
	sbf.append("\n</TR>");
	sbf.append("\n</TABLE>");
	return sbf;
    }

    public StringBuffer getYear(String name, int years) {
	StringBuffer sbf = new StringBuffer();
	sbf.append("<select size=1 name="+name+">");
	sbf.append(MyHtml.getYearOption(1,years));
	sbf.append("</select>");
	return sbf;
    }

    public StringBuffer getYearAndBroker(String call_path, String mid, String aid, int user_level, int file_size_max) {
	Hashtable bhash = getBrokers();

	StringBuffer sbf = new StringBuffer();
	sbf.append("<BR><TABLE>");
	sbf.append("<TR><TD align=center style='font-size: 12pt'>Schedule-D Generator </TD></TR>");

	sbf.append("<TR><TD align=center style='font-size: 10pt'>");
	sbf.append("<I>3WCenter.com is not responsible for any computer generated error.</I>");
	sbf.append("</TD></TR>");

	sbf.append("<TR><TD align=center style='font-size: 10pt'>");
	sbf.append("In order to use this web based application, you need the following four things:");
	sbf.append("</TD></TR>");

	sbf.append("<TR><TD align='center' style='font-size: 10pt'>");
	sbf.append("<table style='font-size: 10pt'>");
	sbf.append("<tr><td><1> 3WCenter.com account.</td></tr>");
	sbf.append("<tr><td><2> Transaction data file from your broker.</td></tr>");
	sbf.append("<tr><td><3> Form 1099 of the year.</td></tr>");
	sbf.append("<tr><td><4> Pre-year holding records if this is your first time.</td></tr>");
	sbf.append("</table>");
	sbf.append("</TD></TR>");

	sbf.append("<TR><TD align=center style='font-size: 10pt'>");
	sbf.append("<I>* Please check your Schedule-D before you submit it to IRS.</I>");
	sbf.append("</TD></TR>");

	sbf.append("</TABLE><BR>");

	sbf.append("<form method='post' action='"+call_path+"'>");
	sbf.append("<table border=1 style='font-size: 10pt'>");

	sbf.append("<tr>");
	sbf.append("<td align=right>");
	sbf.append("Year :");
	sbf.append("</td>");
	sbf.append("<td align=center>");
	sbf.append(getYear("year",10));
	sbf.append("</td>");
	sbf.append("</tr>");

	sbf.append("<tr>");
	sbf.append("<td align=right>");
	sbf.append("Broker :");
	sbf.append("</td>");
	sbf.append("<td>");
	sbf.append(MyHtml.getOptions("broker", bhash));
	sbf.append("</td>");
	sbf.append("</tr>");

	sbf.append("</table>");
	sbf.append("<input type=hidden name=mid value="+mid+">");
	sbf.append("<input type=hidden name=aid value="+aid+">");
	sbf.append("<P align=center><input type=submit value=Continue name=B1 ");
	sbf.append(" style='font-size: 8pt'></P>");
	sbf.append("</form>");
	
	sbf.append("<TABLE>");
	sbf.append("<TR><TD align=center style='font-size: 10pt'>");
	sbf.append("<I>* Transaction data file size is limited to "+file_size_max+"k for this web based application.</I>");
	sbf.append("</TD></TR>");

	sbf.append("<TR><TD align=center style='font-size: 10pt'>");
	sbf.append("<I>If youe transaction data file size is more than "+file_size_max+"k, please contact us.</I>");
	sbf.append("</TD></TR>");
	sbf.append("</TABLE>");
	return sbf;
    }
     
    public Hashtable getBrokers() {
	try {
	    if (ejbdb == null) {
		ejbdb = (new DatabaseEJBQuery()).getEJBDatabaseQuery();
	    }

	    String query = "SELECT * FROM STOCK_BROKERS ORDER BY NAME;";
	    return(ejbdb.selectTwoFieldValueHashtable(query, "NAME", "ID"));
	}
	catch (Exception e) {
	    return null;
	}
    }

    public String getBrokerName(String broker_id) {
	try {
	    if (ejbdb == null) {
		ejbdb = (new DatabaseEJBQuery()).getEJBDatabaseQuery();
	    }

	    String query = "SELECT NAME FROM STOCK_BROKERS WHERE ID="+broker_id+";";
	    return(ejbdb.selectSingleFieldValue(query, "NAME"));
	}
	catch (Exception e) {
	    return null;
	}
    }

    public boolean isBaseYear (String user_name, String broker, String year) {
	try {
	    if (ejbdb == null) {
		ejbdb = (new DatabaseEJBQuery()).getEJBDatabaseQuery();
	    }

	    ArrayList alist = ejbdb.selectUserScheduleDInfo (user_name, broker, year, -1);	    
	    if(alist == null || alist.isEmpty()) {
		return true;
	    }
	}
	catch (Exception e) {
	}
	return false;
    }

    public int findBaseYear (String user_name, String broker, String year) {
	try {
	    if (ejbdb == null) {
		ejbdb = (new DatabaseEJBQuery()).getEJBDatabaseQuery();
	    }	    
	    return ejbdb.findBaseYear(user_name, broker, year);	    
	}
	catch (Exception e) {
	    System.out.println("ScueduleD:findBaseYear:Error:"+e);
	    return -1;
	}
    }

    public boolean isLastYear (String user_name, String broker, String year) {
	try {
	    if (ejbdb == null) {
		ejbdb = (new DatabaseEJBQuery()).getEJBDatabaseQuery();
	    }

	    ArrayList alist = ejbdb.selectUserScheduleDInfo (user_name, broker, year, -1);	    
	    if(alist == null || alist.isEmpty()) {
		return true;
	    }
	}
	catch (Exception e) {
	}
	return false;
    }

    public StringBuffer getBoughtOrSoldDetailRecords(String fid, String tick, int bs) {
	StringBuffer sbf = null;
	try {
	    if (ejbdb == null) {
		ejbdb = (new DatabaseEJBQuery()).getEJBDatabaseQuery();
	    }
	    Vector vb = ejbdb.getBoughtOrSoldDetailRecords(fid, tick, 1);
	    Vector vs = ejbdb.getBoughtOrSoldDetailRecords(fid, tick, -1);
	    sbf = displayBoughtAndSoldDetailRecords(vb, vs);
	}
	catch (Exception e) {
	    System.out.println("ScheduleD:getBoughtOrSoldDetailRecords:Error:"+e);
	}
	return sbf;
    }

    public StringBuffer displayBoughtAndSoldDetailRecords (Vector vb, Vector vs) {
	StringBuffer sbf = new StringBuffer();

	sbf.append("<TABLE width=90% cellSpacing='0' cellPadding=2 border=1>");
	sbf.append("<TR><TD align=center><B>BOUGHT</B></TD><TD align=center><B>SOLD</B></TD></TR>");
	sbf.append("<TR><TD valign=top align=center>");
	sbf.append("<TABLE cellSpacing=0 cellPadding=0 border=1  width=100%>");
	sbf.append("<TR>");
	//sbf.append("<TD align=center>BOUGHT</TD>");
	sbf.append("<TD align=center>COST</TD>");
	sbf.append("<TD align=center>TICK</TD>");
	sbf.append("<TD align=center>SHARES</TD>");
	sbf.append("<TD align=center>PRICE</TD>");
	sbf.append("<TD align=center>DATE</TD>");
	sbf.append("</TR>");
	
	Enumeration enum = null;

	try {
	    if(vb != null) {
		enum = vb.elements();
		while(enum.hasMoreElements()) {
		    sbf.append("<TR>");
		    enum.nextElement();
		    sbf.append("<TD align=right>"+java.lang.Math.abs((new Double(""+enum.nextElement())).floatValue())+"</TD>");
		    sbf.append("<TD align=center>"+enum.nextElement()+"</TD>");
		    sbf.append("<TD align=right>"+enum.nextElement()+"</TD>");
		    sbf.append("<TD align=right>"+enum.nextElement()+"</TD>");
		    sbf.append("<TD align=center>"+enum.nextElement()+"</TD>");
		    sbf.append("</TR>");
		}
	    }
		
	    sbf.append("</TABLE>");
	    sbf.append("</TD>");
	    sbf.append("<TD valign=top align=center>");
	    sbf.append("<TABLE cellSpacing=0 cellPadding=0 border=1 width=100%>");
	    sbf.append("<TR>");
	    //sbf.append("<TD align=center>SOLD</TD>");
	    sbf.append("<TD align=center>COST</TD>");
	    sbf.append("<TD align=center>TICK</TD>");
	    sbf.append("<TD align=center>SHARES</TD>");
	    sbf.append("<TD align=center>PRICE</TD>");
	    sbf.append("<TD align=center>DATE</TD>");
	    sbf.append("</TR>");
	    
	    if(vs != null) {
		enum = vs.elements();
		while(enum.hasMoreElements()) {
		    sbf.append("<TR>");
		    enum.nextElement();
		    sbf.append("<TD align=right>"+java.lang.Math.abs((new Double(""+enum.nextElement())).floatValue())+"</TD>");
		    sbf.append("<TD align=center>"+enum.nextElement()+"</TD>");
		    sbf.append("<TD align=right>"+enum.nextElement()+"</TD>");
		    sbf.append("<TD align=right>"+enum.nextElement()+"</TD>");
		    sbf.append("<TD align=center>"+enum.nextElement()+"</TD>");
		    sbf.append("</TR>");
		}
	    }
	    sbf.append("</TABLE>");
	    sbf.append("</TD></TR>");
	    sbf.append("</TABLE>");
	}
	catch (Exception e) {
	    System.out.println("ScheduleD:displayBoughtAndSoldDetailRecords:Error:"+e);
	}
	return sbf;
    }

    public StringBuffer finalViewRecordSumary (String tick, Vector vb, Vector vs, Vector vhb, Vector vhs) {
	StringBuffer sbf = new StringBuffer();
	Enumeration enumb = null;
	Enumeration enums = null;
	StockRecord rb = null;
	StockRecord rs = null;

	try {
	    int bsz = 0;
	    int ssz = 0;
	    if(vb != null && !vb.isEmpty()) {
		vb.trimToSize();
		bsz = vb.size();
	    }
	    if(vs != null && !vs.isEmpty()) {
		vs.trimToSize();
		ssz = vs.size();
	    }

	    int size1 = java.lang.Math.max(bsz, ssz);
	    if(bsz>0) {
		enumb = vb.elements();
	    }
	    if(ssz>0) {
		enums = vs.elements();
	    }

	    sbf.append("<TR><TD align=center colspan=8><B>"+tick+"</B></TD>");
	    for(int i=0; i<size1;i++) {
		sbf.append("<TR>");
		if(enumb != null && enumb.hasMoreElements()) {
		    rb = (StockRecord)enumb.nextElement();
		    sbf.append("<TD align=right>"+td.format(java.lang.Math.abs(rb.getCost()))+"</TD>");
		    sbf.append("<TD align=right>"+rb.getShare()+"</TD>");
		    sbf.append("<TD align=right>"+td.format(rb.getPrice())+"</TD>");
		    sbf.append("<TD align=right>"+rb.getDate()+"</TD>");
		}
		else {
		    sbf.append("<TD align=center><img src=/images/star_green.gif></TD>");
		    sbf.append("<TD align=center><img src=/images/star_green.gif></TD>");
		    sbf.append("<TD align=center><img src=/images/star_green.gif></TD>");
		    sbf.append("<TD align=center><img src=/images/star_green.gif></TD>");
		}
		if(enums != null && enums.hasMoreElements()) {
		    rs = (StockRecord)enums.nextElement();
		    sbf.append("<TD align=right>"+td.format(java.lang.Math.abs(rs.getCost()))+"</TD>");
		    sbf.append("<TD align=right>"+rs.getShare()+"</TD>");
		    sbf.append("<TD align=right>"+td.format(rs.getPrice())+"</TD>");
		    sbf.append("<TD align=right>"+rs.getDate()+"</TD>");
		}
		else {
		    sbf.append("<TD align=center><img src=/images/star_green.gif></TD>");
		    sbf.append("<TD align=center><img src=/images/star_green.gif></TD>");
		    sbf.append("<TD align=center><img src=/images/star_green.gif></TD>");
		    sbf.append("<TD align=center><img src=/images/star_green.gif></TD>");
		}
		sbf.append("</TR>");
	    }

	    bsz = 0;
	    ssz = 0;
	    enumb = null;
	    enums = null;

	    if(vhb != null && !vhb.isEmpty()) {
		vhb.trimToSize();
		bsz = vhb.size();
	    }
	    if(vhs != null && !vhs.isEmpty()) {
		vhs.trimToSize();
		ssz = vhs.size();
	    }

	    size1 = java.lang.Math.max(bsz, ssz);

	    if(bsz>0) {
		enumb = vhb.elements();
	    }
	    if(ssz>0) {
		enums = vhs.elements();
	    }

	    for(int i=0; i<size1;i++) {
		sbf.append("<TR>");
		if(enumb != null && enumb.hasMoreElements()) {
		    rb = (StockRecord)enumb.nextElement();
		    sbf.append("<TD align=right>"+td.format(java.lang.Math.abs(rb.getCost()))+"</TD>");
		    sbf.append("<TD align=right>"+rb.getShare()+"</TD>");
		    sbf.append("<TD align=right>"+td.format(rb.getPrice())+"</TD>");
		    sbf.append("<TD align=right>"+rb.getDate()+"</TD>");
		}
		else {
		    sbf.append("<TD align=center><img src=/images/star_green.gif></TD>");
		    sbf.append("<TD align=center><img src=/images/star_green.gif></TD>");
		    sbf.append("<TD align=center><img src=/images/star_green.gif></TD>");
		    sbf.append("<TD align=center><img src=/images/star_green.gif></TD>");
		}
		if(enums != null && enums.hasMoreElements()) {
		    rs = (StockRecord)enums.nextElement();
		    sbf.append("<TD align=right>"+td.format(java.lang.Math.abs(rs.getCost()))+"</TD>");
		    sbf.append("<TD align=right>"+rs.getShare()+"</TD>");
		    sbf.append("<TD align=right>"+td.format(rs.getPrice())+"</TD>");
		    sbf.append("<TD align=right>"+rs.getDate()+"</TD>");
		}
		else {
		    sbf.append("<TD align=center><img src=/images/star_green.gif></TD>");
		    sbf.append("<TD align=center><img src=/images/star_green.gif></TD>");
		    sbf.append("<TD align=center><img src=/images/star_green.gif></TD>");
		    sbf.append("<TD align=center><img src=/images/star_green.gif></TD>");
		}
		sbf.append("</TR>");
	    }
	}
	catch (Exception e) {
	    System.out.println("ScheduleD:displayBoughtAndSoldDetailRecords:Error:"+e);
	}
	return sbf;
    }

    public StringBuffer displayElementsOfVV (Vector vv) {
	StringBuffer sbf = new StringBuffer();
	Enumeration enum2 = null;
	Vector v = null;
	Enumeration enum1 = vv.elements();
	sbf.append("<TABLE width=100% border=1>");
	try {
	    while(enum1.hasMoreElements()) {
		v = (Vector)enum1.nextElement();
		enum2 = v.elements();
		sbf.append("<TR>");
		while(enum2.hasMoreElements()) {
		    sbf.append("<TD>"+enum2.nextElement()+"</TD>");
		}
		sbf.append("</TR>");
	    }
	    sbf.append("</TABLE>");
	}
	catch (Exception e) {
	    System.out.println(e);
	}
	return sbf;
    }
   
    public StringBuffer viewTransactionDetailRecords (HttpServletRequest request, String call_path, String mid, 
						      String aid, String user_name, 
						      int user_level, String year, String broker, String status, 
						      String fid, String vid, String error, int delete_level) {
	String record_status = "0";
	StringBuffer sbf = new StringBuffer();
	if(year == null || broker == null || status == null || fid == null || vid == null) {
	    return (new StringBuffer("Data not found"));
	}

	String stick = request.getParameter("stick");

	String sort = request.getParameter("sort");
	int order = 0;
	if(sort != null) {
	    order = Integer.parseInt(sort);
	}

	Vector v = null;
	try {
	    if (ejbdb == null) {
		ejbdb = (new DatabaseEJBQuery()).getEJBDatabaseQuery();
	    }
	    //===========================================================
	    // 0: [order by date] 1: [order by bs] 2: [order by tick]
	    //===========================================================
	    if(stick == null) {
		v = ejbdb.selectScheduleDDetailRecords(fid, record_status, order);
	    }
	    else {
		v = ejbdb.selectScheduleDDetailRecords(fid, record_status, order, stick);
	    }
	}
	catch (Exception e) {
	    System.out.println("ScheduleD:"+e);
	    return sbf.append("Loading Data Error.");
	}

	if(v == null || v.isEmpty()) {
	    return sbf.append("Data not found.");
	}

	sbf.append("<TABLE width=90% border=1>");
	sbf.append("<TR><TD align=center colspan=6><B>Transaction Data of YEAR ["+year+"]");
	sbf.append(" BROKER ["+getBrokerName(broker)+"] Detail Records</TD></TR>");
	sbf.append("</TD></TR>");	

	StringBuffer fsbf = new StringBuffer();
	fsbf.append("<FORM method=post action="+call_path+">");
	fsbf.append("<input type=hidden name=mid value="+mid+">");
	fsbf.append("<input type=hidden name=aid value="+aid+">");
	fsbf.append("<input type=hidden name=fid value="+fid+">");
	fsbf.append("<input type=hidden name=vid value="+vid+">");
	fsbf.append("<input type=hidden name=stid value="+status+">");
	fsbf.append("<input type=hidden name=bid value="+broker+">");
	fsbf.append("<input type=hidden name=yid value="+year+">");

	sbf.append("<BR>");
	if(error != null) {
	    sbf.append("<TR><TD align=center colspan=6><img src=/images/star.gif><I>"+error+"</I></TD></TR>");
	}

	sbf.append("<TR>");
	if(order == 1) {
	    sbf.append("<TD align=center>Bought/Sold</TD>");
	}
	else {
	    sbf.append(fsbf);
	    sbf.append("<TD align=center>Bought/Sold<input type='image' src='/images/sort.gif' border='0'></TD>");
	    sbf.append("<input type=hidden name=sort value=1>");
	    sbf.append("</FORM>");
	}

	sbf.append("<TD align=center>COST</TD>");
	if(order == 2) {
	    sbf.append("<TD align=center>TICK</TD>");
	}
	else {
	    sbf.append(fsbf);
	    sbf.append("<TD align=center>TICK<input type='image' src='/images/sort.gif' border='0'></TD>");
	    sbf.append("<input type=hidden name=sort value=2>");
	    sbf.append("</FORM>");
	}
	sbf.append("<TD align=center>SHARES</TD>");
	sbf.append("<TD align=center>PRICE</TD>");
	
	if(order == 0) {
	    sbf.append("<TD align=center>DATE</TD>");
	}
	else {
	    sbf.append(fsbf);
	    sbf.append("<TD align=center>DATE<input type='image' src='/images/sort.gif' border='0'></TD>");
	    sbf.append("<input type=hidden name=sort value=0>");
	    sbf.append("</FORM>");
	}
	sbf.append("<TR>");

	Enumeration enum = v.elements();
	String bs    = null;
	double cost  = 0.0;
	String tick  = null;
	int share    = 0;
	double price = 0.0;
	String date  = null;
	
	try {
	    while(enum.hasMoreElements()) {
		bs    = (String)enum.nextElement();
		cost  = Double.parseDouble(""+enum.nextElement());
		tick  = (String)enum.nextElement();
		share = (new Double(""+enum.nextElement())).intValue();
		price = Double.parseDouble(""+enum.nextElement());
		date  = (String)enum.nextElement();
		
		sbf.append("<TR>");
		sbf.append("<TD align=center>"+bs+"</TD>");
		sbf.append("<TD align=right>"+cost+"</TD>");
		sbf.append("<TD align=center>"+tick+"</TD>");
		sbf.append("<TD align=right>"+share+"</TD>");
		sbf.append("<TD align=right>"+price+"</TD>");
		sbf.append("<TD align=center>"+date+"</TD>");
		sbf.append("</TR>");
	    }
	}
	catch (Exception e) {
	    System.out.println("viewTransactionDetailRecords:Error:100:"+e);
	}

	sbf.append("</TABLE>");
	enum = null;
	v    = null;
	return sbf;
    }

    public Vector addElements(Vector v1, Vector v2) {
	Vector v = new Vector();
	Enumeration enum = v1.elements();
	while(enum.hasMoreElements()) {
	    v.add(enum.nextElement());
	}

	enum = v2.elements();
	while(enum.hasMoreElements()) {
	    v.add(enum.nextElement());
	}
	return v;
    }

    public StockRecord addRecords(StockRecord r1, StockRecord r2) {
	StockRecord r = new StockRecord();
	double c1 = java.lang.Math.abs(r1.getCost());
	double c2 = java.lang.Math.abs(r2.getCost());
	int s1 = r1.getShare();
	int s2 = r2.getShare();
	double p1 = r1.getPrice();
	double p2 = r2.getPrice();
	int d1 = r1.getDateIntValue();
	int d2 = r2.getDateIntValue();
	
	if(d1>d2) {
	    r.setBuySell(r1.getBuySell());
	    r.setCost(java.lang.Math.abs(c1+c2));
	    r.setTick(r1.getTick());
	    r.setShare(r1.getShare()+r2.getShare());
	    double p = (p1*s1+p2*s2)/(s1+s2);
	    r.setPrice(p);
	    r.setDate(d1);
	}
	else {
	    r.setBuySell(r2.getBuySell());
	    r.setCost(java.lang.Math.abs(c1+c2));
	    r.setTick(r2.getTick());
	    r.setShare(r1.getShare()+r2.getShare());
	    double p = (p1*s1+p2*s2)/(s1+s2);
	    r.setPrice(p);
	    r.setDate(d2);
	}	

	return r;
    }

    public StockRecord subtractRecords(StockRecord r1, StockRecord r2) {
	StockRecord r = new StockRecord();
	double c1 = java.lang.Math.abs(r1.getCost());
	double c2 = java.lang.Math.abs(r2.getCost());
	int s1 = r1.getShare();
	int s2 = r2.getShare();
	double p1 = r1.getPrice();
	double p2 = r2.getPrice();
	int d1 = r1.getDateIntValue();
	int d2 = r2.getDateIntValue();
	double p = 0.0;
	if(s1>s2) {
	    r.setTick(r1.getTick());
	    r.setBuySell(r1.getBuySell());
	    r.setShare(s1-s2);
	    r.setPrice(p1);
	    r.setCost(java.lang.Math.abs(c1*(s1-s2)/s1));
	    r.setPrice(p1);
	    r.setDate(d1);
	}

	if(s1<s2) {
	    r.setTick(r2.getTick());
	    r.setBuySell(r2.getBuySell());
	    r.setShare(s2-s1);
	    r.setPrice(p2);
	    r.setCost(java.lang.Math.abs(c2*(s2-s1)/s2));
	    r.setPrice(p2);
	    r.setDate(d2);
	}

	if(s1==s2) {
	    return null;
	}
	return r;
    }

    public StockRecord splitRecord(StockRecord r, int return_shares) {
	double cost   = java.lang.Math.abs(r.getCost());
	int shares    = r.getShare();
	
	if(shares < return_shares) {
	    return null;
	}
	
	if(shares == return_shares) {
	    return r;
	}
	
	r.setShare(return_shares);
	r.setCost(java.lang.Math.abs(cost*return_shares/shares));
	return r;
    }

    public boolean update1099Status(String user_name, String year, String broker, int status) {
	try {
	    if (ejbdb == null) {
		ejbdb = (new DatabaseEJBQuery()).getEJBDatabaseQuery();
	    }

	    if(ejbdb.updateUserScheduleDStatus (user_name, year, broker, status)>0) {
		return true;
	    }
	}
	catch(Exception e) {
	    System.out.println("ScheduleD:update1099Status:"+e);
	    return false;
	}
	return false;
    }
}









